<?php header("Content-Type: text/html;  charset=ISO-8859-1",true) ?>
<?php include "inc/funcoes.inc"; ?>
<?php

$opt= $_REQUEST["opt"];

if($opt=="choice")
{
	$strSql = "Select qstType, qst1, qst2, qst3, qst4, qst5, qst7, qst9, qst11, qst13_A, qst13_B, qst13_C, qst14, qst15";
}
else
{
	$strSql = "Select *";
}

$strSql .= " from db_survey_questionnaire ";

$rs = execQuery($strSql);

$header="ID\t";

for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
{
	$fldName= $rs->FetchField($i);
	$header .= $fldName->name . "\t";

	//while (!$rs->EOF) {
	//	$header .= $rs->fields[$i] . "\t";
	//	$rs->MoveNext();
	//}

	//$header .= "\n";
	//$rs->MoveFirst();
}

$header .= "\n";

$rs->MoveFirst();

$data = "";

while (!$rs->EOF)
{
	$count = $rs->CurrentRow() + 1;
	$data .= "$count\t";
	for ($i=0, $max=$rs->FieldCount(); $i < $max; $i++)
	{
		$data .= $rs->fields[$i] . "\t";
	}
	$data .= "\n";
	$rs->MoveNext();
}



header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=survey_spreadsheet_$opt.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo "$header$data";


?>